package com.vr.xuecheng.content.controller;

import com.vr.xuecheng.base.dto.BasePageParamsDTO;
import com.vr.xuecheng.base.response.PageResult;
import com.vr.xuecheng.base.response.Result;
import com.vr.xuecheng.base.valid.ValidationGroup;
import com.vr.xuecheng.content.model.dto.CourseAddOrUpdateParamsDTO;
import com.vr.xuecheng.content.model.dto.QueryCourseParamsDTO;
import com.vr.xuecheng.content.model.vo.AddOrUpdateCourseResponseVO;
import com.vr.xuecheng.content.model.vo.CourseBasePageVO;
import com.vr.xuecheng.content.model.vo.CourseBaseVO;
import com.vr.xuecheng.content.model.vo.CoursePreviewVO;
import com.vr.xuecheng.content.service.ICourseBaseService;
import com.vr.xuecheng.content.service.ICoursePublishService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * 课程基本信息
 *
 * @author hsh
 */
@Slf4j
@RestController
@Tag(name = "课程基本信息")
@RequestMapping("/course")
@RequiredArgsConstructor
public class CourseBaseController {

    private final ICourseBaseService courseBaseService;
    private final ICoursePublishService coursePublishService;


    /**
     * @param id 课程id
     * @return {@link CourseBaseVO } 结果
     * 课程查询根据id
     */
    @Operation(summary = "根据课程id查询课程信息")
    @GetMapping("/{id}")
    public CourseBaseVO getCourseBaseById(@PathVariable("id") Long id)  {
        return courseBaseService.getCourseBaseById(id);
    }

    /**
     * @param courseAddOrUpdateParamsDTO 新增课程参数
     * @return {@link Result }<{@link String }> 结果
     * 新增课程
     */
    @Operation(summary = "新增课程")
    @PostMapping
    public AddOrUpdateCourseResponseVO add(@RequestBody @Validated(ValidationGroup.Insert.class) CourseAddOrUpdateParamsDTO courseAddOrUpdateParamsDTO) {
        return courseBaseService.add(courseAddOrUpdateParamsDTO);
    }

    /**
     * @param courseAddOrUpdateParamsDTO 参数
     * @return {@code AddOrUpdateCourseResponseVO } 结果
     * 更新课程信息
     */
    @Operation(summary = "修改课程")
    @PutMapping
    public AddOrUpdateCourseResponseVO update(@RequestBody @Validated(ValidationGroup.Update.class) CourseAddOrUpdateParamsDTO courseAddOrUpdateParamsDTO) {
        return courseBaseService.updateCourseBase(courseAddOrUpdateParamsDTO);
    }

    /**
     * @param basePageParamsDTO 分页参数
     * @param queryCourseParamsDTO 分页条件参数
     * @return {@link PageResult }<{@link CourseBasePageVO }> 分页结果
     */
    @Operation(summary = "课程列表分页查询")
    @PostMapping("/list")
    public PageResult<CourseBasePageVO> page(BasePageParamsDTO basePageParamsDTO, @RequestBody(required = false) QueryCourseParamsDTO queryCourseParamsDTO) {
        return courseBaseService.page(basePageParamsDTO, queryCourseParamsDTO);
    }

    @Operation(summary = "获取课程")
    @GetMapping("/whole/{course-id}")
    public CoursePreviewVO getCourseById(@PathVariable("course-id") Long courseId) {
        return coursePublishService.getCoursePreviewInfo(courseId);
    }

}
